package com.lzs.adx.web.modules.job.task;

import cn.hutool.core.util.ReflectUtil;
import com.lzs.adx.web.modules.adx.dto.AccountDTO;
import com.lzs.adx.web.modules.adx.dto.ReportTotalDTO;
import com.lzs.adx.web.modules.adx.service.AccountService;
import com.lzs.adx.web.modules.adx.service.ReportService;
import com.lzs.adx.web.modules.adx.service.ReportTotalService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 假回传比例控制器
 */
@Component
@Slf4j
public class FakePerCallBackTask implements ITask{

    @Autowired
    private AccountService accountService;

    @Autowired
    private ReportTotalService reportTotalService;

    @Autowired
    private ReportService reportService;

    @Override
    public void run(String params) {

        Map paramMap=new HashMap<String,Object>();
        paramMap.put("fakePerNotNull",true);
        List<AccountDTO> list = accountService.list(paramMap);
        //便利账户
        for (AccountDTO accountDTO : list) {
            Map prams=new HashMap<String,Object>();
            prams.put("dspId",accountDTO.getId());
            List<ReportTotalDTO> data = reportTotalService.list(prams);
            for (ReportTotalDTO datum : data) {
                Long cpcTotal = datum.getCpcTotal();
                String sspKey = accountDTO.getSspKey();

                //获取转化的值
                Object fieldValue = ReflectUtil.getFieldValue(datum, sspKey);
                if(Objects.isNull(fieldValue)){
                    fieldValue=0L;
                }
                Long total = Long.valueOf(fieldValue.toString());
                //获取转化的比例
                BigDecimal multiply = new BigDecimal(cpcTotal).multiply(accountDTO.getFakePer());
                long l = multiply.longValue();
//                if(l<total){
//                    reportService.list()
//                }

            }


        }



    }
}
